define(function (require, exports, module) {
    var $ = require("jquery");
    require("pagination");
    var util = require("util");
    var ui = require("ui");
    var angular = require("angular");
    var api_prefix = G_CONFIG["api_prefix"] + 'qmyx'; //api前缀

    var ditchSourceModule = angular.module('ditchSourceBrokerModule', []);

    function ditchSourceService($http, $q, $location) {
        var service = {
            brokers: [],//经纪人列表
            filter: {pageSize: 10},

            initData: function () {
                var p = service.filter;
                service.query(p.pageIndex || 1, p.pageSize || 10, p.keyword || '');
            },
            query: function (pageIndex, pageSize, keyword) {
                angular.extend(service.filter, {pageIndex: pageIndex, pageSize: pageSize, keyword: keyword});
                $http.get(api_prefix + '/channel-source/channel-regbroker-list', {params: service.filter})
                    .then(function (res) {
                        var retCode = res.data.retCode;
                        if (retCode == 0) {
                            var data = res.data.data;
                            service.brokers = data.items;
                            service.total = data.total;
                            service.filter.pageIndex = pageIndex;
                        } else {
                            ui.showErrTip(res.data.errMsg);
                            return false;
                        }
                    });
            },
            initViewBrokerDialog: function ($data, $dialog, $dialogScope, ditchsource){
                service.filter.channel_source_id = ditchsource.channel_source_id;
                service.initData();
                $dialogScope.brokerSvr = service;

                $dialogScope.getDitchSourceBrokerData = function (page) {
                    service.filter.pageIndex = page;
                    service.initData();
                }
            }
        };

        return service;
    }

    ditchSourceModule.factory('ditchSourceBrokerSvr', ['$http', '$q', '$location', ditchSourceService]);

    module.exports = ditchSourceModule;
});